package com.bjgzy.courselive.di.module;

import android.graphics.PorterDuff;
import android.graphics.drawable.LayerDrawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.RatingBar;

import com.bjgzy.courselive.mvp.contract.CourseLiveHomeContract;
import com.bjgzy.courselive.mvp.model.CourseLiveHomeModel;
import com.bjgzy.module_couselive.R;
import com.blankj.utilcode.util.ObjectUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.CourseLiveHomeData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.jess.arms.di.scope.FragmentScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-7-30 9:29:12
 */
@Module
public abstract class CourseLiveHomeModule {

    @Binds
    abstract CourseLiveHomeContract.Model bindCourseLiveHomeModel(CourseLiveHomeModel model);

    @FragmentScope
    @Provides
    static List<CourseLiveHomeData> provideList() {
        return new ArrayList<>();
    }

    @FragmentScope
    @Provides
    static BaseQuickAdapter<CourseLiveHomeData, AutoBaseViewHolder> provideActivityAdapter(List<CourseLiveHomeData> list) {
        return new BaseQuickAdapter<CourseLiveHomeData, AutoBaseViewHolder>(R.layout.courselive_rv_item_home, list) {
            @Override
            protected void convert(AutoBaseViewHolder helper, CourseLiveHomeData item) {
                RatingBar ratingBar = helper.getView(R.id.ratingBar);
                ratingBar.setRating(item.getStar());
                LayerDrawable ld_stars = (LayerDrawable) ratingBar.getProgressDrawable();
                ld_stars.getDrawable(2).setColorFilter(helper.itemView.getContext().getResources().getColor(R.color.public_color_orange), PorterDuff.Mode.SRC_ATOP);

                Glide.with(helper.itemView.getContext())
                        .load(item.getPreImage())
                        .apply(RequestOptions.placeholderOf(R.drawable.public_img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_avatar));
                helper.setText(R.id.tv_shop, item.getShopName());
//                helper.setText(R.id.tv_study_no, String.format(helper.itemView.getContext().getString(R.string.courselive_stydy_times),item.get));
                helper.setText(R.id.tv_title, item.getTitle());
                helper.setText(R.id.tv_price, ObjectUtils.isEmpty(item.getPrice())?"¥0":"¥"+item.getPrice());



            }

        };
    }

    @FragmentScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManger(CourseLiveHomeContract.View view) {
        return new LinearLayoutManager(view.getActivity());
    }
}